#define  _CRT_SECURE_NO_WARNINGS
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
    vector<string> ret;
    void bfs(TreeNode* root, string s)
    {
        TreeNode* pL = root->left, * pR = root->right;
        if (s.size()) s += "->";
        s += to_string(root->val);
        if (!pL && !pR)
        {
            ret.push_back(s);
            return;
        }
        if (pL) bfs(pL, s);
        if (pR) bfs(pR, s);
    }
public:
    vector<string> binaryTreePaths(TreeNode* root) {
        bfs(root, string());
        return ret;
    }
};